home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / andere sprachen / oberonv4 / text / prog.guide.text (.txt) < prev    next >
Encoding:
Oberon Text  |  1996-03-19  |  33.8 KB  |  771 lines

  1. Syntax10.Scn.Fnt
  2. StyleElems
  3. Alloc
  4. Header
  5. Text1
  6. FoldElems
  7. Syntax10.Scn.Fnt
  8. StyleElems
  9. Alloc
  10. TwoCols
  11. LinkElems
  12. Alloc
  13. Prog.Guide.Text
  14. Prog.Guide.Text
  15. Prog.Guide.Text
  16. Prog.Guide.Text
  17. Prog.Guide.Text
  18. Prog.Guide.Text
  19. Prog.Guide.Text
  20. Prog.Guide.Text
  21. Prog.Guide.Text
  22. Prog.Guide.Text
  23. Prog.Guide.Text
  24. Prog.Guide.Text
  25. System log text    Oberon.Log
  26. Create an empty text    text := TextFrames.Text("");
  27. Create a new text and initialize it from     text := TextFrames.Text(name);
  28.     disk file name
  29. Write to system log    
  30. Insert buffer buf at position pos in text    Texts.Insert(text, pos, buf);
  31. Append buffer buf to text    Texts.Append(text, buf);
  32. Read sequential characters    
  33. Scan sequential symbols    
  34. Save stretch [beg, end) of text in     NEW(buf); Texts.OpenBuf(buf);
  35.     buffer buf    Texts.Save(text, beg, end, buf);
  36. Create a text    
  37. Read from a text    
  38. Scan a text    
  39. Text1
  40. Syntax10.Scn.Fnt
  41. StyleElems
  42. Alloc
  43. TwoCols
  44. LinkElems
  45. Alloc
  46. Prog.Guide.Text
  47. Prog.Guide.Text
  48. Prog.Guide.Text
  49. Prog.Guide.Text
  50. Prog.Guide.Text
  51. Prog.Guide.Text
  52. Prog.Guide.Text
  53. Prog.Guide.Text
  54. Prog.Guide.Text
  55. Prog.Guide.Text
  56. System parameter list    Oberon.Par
  57. Viewer from which command is issued    Oberon.Par.vwr
  58. Frame from which command is issued    Oberon.Par.frame
  59. Text from which command is issued    Oberon.Par.text
  60. Start of parameter list    Oberon.Par.pos
  61. The most recent selection in the system    Oberon.GetSelection(text, beg, end, time)
  62. The marked viewer    Oberon.MarkedViewer()
  63. Open scanner for parameter list    
  64. Was command issued from a menu    IF Oberon.Par.frame = Oberon.Par.vwr.dsc THEN
  65.     frame of any viewer?
  66. Parameters in the selection    
  67. The marked viewer as parameter    
  68. Menu commands implicitly refer to the viewer     
  69. which contains the menu frame.
  70. Text1
  71. Syntax10.Scn.Fnt
  72. StyleElems
  73. Alloc
  74. TwoCols
  75. FoldElems
  76. Syntax10.Scn.Fnt
  77. ---------------
  78. Most Oberon viewers have 2 frames (a menu frame and a contents frame). Such viewers are opened with MenuViewers.New instead of Viewers.Open. MenuViewers.New needs the following parameters:
  79. - a menu frame
  80. - a contents frame
  81. - the height of the menu (usually always TextFrames.menuH)
  82. - the coordinates of a point on the upper edge of the new viewer
  83. ---------------
  84. Syntax10.Scn.Fnt
  85. ---------------
  86. A viewer is normally closed interactively with the command System.Close. It can, however, also be closed from a program with Viewers.Close. The contents of the viewer is not saved automatically. A viewer that was closed unintentionally can be reopened with the command System.Recall.
  87. ---------------
  88. MarkElems
  89. Alloc
  90. Syntax10.Scn.Fnt
  91. FoldElems
  92. Syntax10.Scn.Fnt
  93. Viewers.This(x, 0)
  94. Syntax10.Scn.Fnt
  95. v.state > 1
  96. Syntax10.Scn.Fnt
  97. Viewers.Next(v)
  98. Syntax10.Scn.Fnt
  99. x + v.W
  100. ---------------
  101. This can be useful for finding a specific viewer or a viewer with a certain contents.
  102. PROCEDURE TraverseAllViewers;
  103.     VAR x: INTEGER; v: Viewers.Viewer;
  104. BEGIN
  105.     x := 0;
  106.     WHILE x < Display.Width DO
  107.         v := 
  108. bottom viewer in x track
  109.         WHILE 
  110. v is not the filler viewer
  111.             (*... process viewer v ...*)
  112.             v := 
  113. viewer above v
  114.         END;
  115.         x := 
  116. x of next track
  117. END TraverseAllViewers;
  118. ---------------
  119. Syntax10.Scn.Fnt
  120. ---------------
  121. This message is normally forwarded to the frames of the viewer.
  122. ---------------
  123. Syntax10.Scn.Fnt
  124. LinkElems
  125. Alloc
  126. MyProg.Guide.Text
  127. ---------------
  128. Traverse all viewers on the screen (
  129. ) and find the one with the smallest value of
  130. v.dsc.next(TextFrames.Frame).time.
  131. ---------------
  132. Opening a viewer   
  133.     v := MenuViewers.New(menuF, contF, menuH, x, y)
  134. Closing a viewer  
  135.     Viewers.Close(v)
  136. Finding the viewer at position (x, y)    v := Viewers.This(x, y)
  137. Traversing all viewers on the screen  
  138. Broadcasting a message to all viewers  
  139.     Viewers.Broadcast(msg)
  140. Getting the focus viewer    v := Oberon.FocusViewer
  141. Getting the marked viewer    v := Oberon.MarkedViewer()
  142. Getting the viewer containing the most recent text selection  
  143. Text1
  144. Syntax10.Scn.Fnt
  145. StyleElems
  146. Alloc
  147. TwoCols
  148. LinkElems
  149. Alloc
  150. Prog.Guide.Text
  151. Prog.Guide.Text
  152. Prog.Guide.Text
  153. Prog.Guide.Text
  154. Prog.Guide.Text
  155. Prog.Guide.Text
  156. Prog.Guide.Text
  157. Prog.Guide.Text
  158. Prog.Guide.Text
  159. Prog.Guide.Text
  160. Prog.Guide.Text
  161. Position of star-shaped pointer    x := Oberon.Pointer.X;
  162.                 y := Oberon.Pointer.Y;
  163. The marked viewer    Oberon.MarkedViewer()
  164. Position of the mouse    x := Oberon.Mouse.X;
  165.                 y := Oberon.Mouse.Y;
  166. Viewer which contains mouse    Viewers.This(Oberon.Mouse.X, Oberon.Mouse.Y)
  167. Focus viewer    Oberon.FocusViewer
  168. Is viewer v a standard text viewer?    IF (v IS MenuViewers.Viewer) &
  169.                     (v.dsc IS TextFrames.Frame) &
  170.                     (v.dsc.next IS TextFrames.Frame) THEN ...
  171. Has viewer v a text frame as menu frame?    IF v.dsc IS TextFrames.Frame THEN ...
  172. Has viewer v a text frame as main frame?    IF (v.dsc # NIL) &
  173.                     (v.dsc.next IS TextFrames.Frame) THEN ...
  174. The menu frame of a text viewer v    v.dsc(TextFrames.Frame)
  175. The menu text of a text viewer v    v.dsc(TextFrames.Frame).text
  176. The main frame of a text viewer v    v.dsc.next(TextFrames.Frame)
  177. The main text of a text viewer v    v.dsc.next(TextFrames.Frame).text
  178. The most recent selection    Oberon.GetSelection(text, beg, end, time)
  179. Is the command executed from the menu    v := Oberon.Par.vwr;
  180.     frame?    IF (Oberon.Par.frame IS TextFrames.Frame) &
  181.                     (v.dsc = Oberon.Par.frame) THEN ...
  182. Placement of the viewer in the user track    Oberon.AllocateUserViewer(
  183.     of the display which contains the mouse        Oberon.Mouse.X, x, y)
  184. Placement of the viewer in the system track    Oberon.AllocateSystemViewer(
  185.     of the display which contains the mouse        Oberon.Mouse.X, x, y)
  186. Open a new text viewer: x and y are     text := TextFrames.Text(name);
  187.     determined by AllocateUserViewer or    v := MenuViewers.New(
  188.     AllocateSystemViewer        TextFrames.NewMenu(name, cmds),
  189.                     TextFrames.NewText(text, 0),
  190.                     TextFrames.menuH, x, y)
  191. Open a viewer    
  192. Text1
  193. Syntax10.Scn.Fnt
  194. StyleElems
  195. Alloc
  196. TwoCols
  197. LinkElems
  198. Alloc
  199. Prog.Guide.Text
  200. Prog.Guide.Text
  201. Prog.Guide.Text
  202. Prog.Guide.Text
  203. Prog.Guide.Text
  204. Prog.Guide.Text
  205. Prog.Guide.Text
  206. Prog.Guide.Text
  207. Prog.Guide.Text
  208. Prog.Guide.Text
  209. Has viewer v a main frame?    IF (v.dsc # NIL) &
  210.                     (v.dsc.next IS TextFrames.Frame) THEN ...
  211. The focus viewer    Oberon.FocusViewer
  212. Text of text frame f    f.text
  213. Position of first displayed character    f.org
  214. A caret is set in text frame f    IF f.hasCar THEN ...
  215. Position of the caret, if one is set    IF f.hasCar THEN pos := f.carloc.pos END;
  216. A selection exists in text frame f    IF f.hasSel THEN ...
  217. Start of the selection, if one exists    IF f.hasSel THEN pos := f.selbeg.pos END;
  218. End of the selection, if one exists    IF f.hasSel THEN pos := f.selend.pos END;
  219. Set the caret at pos in text frame f    Oberon.PassFocus(v);
  220.     installed in menu viewer v    TextFrames.SetCaret(f, beg, end);
  221. Select stretch [beg, end) in text frame f    TextFrames.SetSelection(f, beg, end);
  222. Scroll text such that line with origin at org    TextFrames.RemoveSelection(f);
  223.     will be displayed on top of the viewer    TextFrames.RemoveCaret(f);
  224.                 Oberon.RemoveMarks(f.X, f.Y, f.W, f.H);
  225.                 TextFrames.Show(f, org);
  226. Delete the selected text in the marked viewer    
  227. Copy the most recent selection to the caret's position    
  228. A caret is only allowed if the viewer which manages the frame is the focus viewer.
  229. If a caret is displayed (f.car > 0), it must be removed prior to using TextFrames.SetCaret.
  230. Prior to using TextFrames.Show, the caret, the selection, the mouse cursor, and the pointer must be removed.
  231. The Caret is removed either by a call of TextFrames.RemoveCaret(f) or as a consequence of Oberon.PassFocus(v).
  232. Text1
  233. Syntax10.Scn.Fnt
  234. StyleElems
  235. Alloc
  236. TwoCols
  237. LinkElems
  238. Alloc
  239. Prog.Guide.Text
  240. Prog.Guide.Text
  241. Prog.Guide.Text
  242. Prog.Guide.Text
  243. Prog.Guide.Text
  244. Prog.Guide.Text
  245. Prog.Guide.Text
  246. Open a new file name    f := Files.New(name);
  247. Open an existing file name    f := Files.Old(name);
  248. Write buffers to disk sectors    Files.Close(f);
  249. Write buffers to disk and register file f in directory    Files.Register(f);
  250. Sequential read access through rider r    Files.Set(r, f, 0);
  251.                 Files.Read(r, ch); Files.Read(r, ch);
  252. Sequential write access through rider r    Files.Set(r, f, 0);
  253.                 Files.Write(r, ch); Files.Write(r, ch);
  254. Random access at position pos    Files.Set(r, f, pos);
  255.                 Files.Read(r, ch); ... Files.Write(r, ch);
  256. Read/write a record a of type T    Files.ReadBytes(r, a, SIZE(T));
  257.                 Files.WriteBytes(r, a, SIZE(T));
  258. Read/write a record of type T accessed    Files.ReadBytes(r, p^, SIZE(T));
  259.     with a pointer p    Files.WriteBytes(r, p^, SIZE(T));
  260. Opening another rider for the same file    Files.Set(newR, Files.Base(r), Files.Pos(r))
  261. Text1
  262. Text1
  263. Syntax10.Scn.Fnt
  264. StyleElems
  265. Alloc
  266. Text2
  267. TwoCols
  268. Module In provides a set of basic routines for formatted input of characters, character sequences, numbers, and names. It assumes a standard input stream with a current position that can be reset. Usually the input stream is the text immediately following the most recently invoked command. If this text starts with the character ^ the current position is set to the beginning of the most recent selection (if no selection exists, Done is set to FALSE). If the text starts with the character * the current position is set to the beginning of the text in the marked viewer (if no viewer is marked, Done is set to FALSE). The end of the input stream is the end of the text containing the current position.
  269. Start reading process    In.Open or In.OpenText(t, pos)
  270. Read a character    In.Char(ch)
  271.     Usually you want to skip leading blanks    WHILE In.Done & (ch = " ") DO In.Char(ch) END;
  272. Read an integer number    In.Int(i) or In.LongInt(li)
  273. Read a real number    In.Real(r) or In.LongReal(lr)
  274. Read a name or a string    In.Name(s) or In.String(s)
  275. Read next symbol    IF In.Next() = In.name THEN
  276.     In.char, In.int, In.name, In.string,        In.Name(s)
  277.     In.real, In.longReal,    ELSIF In.Next() = In.string THEN
  278.     and In.inval        In.String(s)
  279.                 ELSE ...
  280. Determine success of the last operation    IF In.Done THEN ...
  281. Text1
  282. Syntax10.Scn.Fnt
  283. StyleElems
  284. Alloc
  285. Text2
  286. TwoCols
  287. Module Out provides a set of basic routines for formatted output of characters, numbers, and strings. It assumes a standard output stream to which the symbols are written.
  288. Start writing process    
  289.     Usually you want to write into the system log which does not need an Out.Open call.
  290.     Open a new output viewer    Out.Open
  291.     Redirect output to System.Log again    Out.Close
  292. Write a character    Out.Char(ch)
  293. Write an integer number    Out.Int(i, 0)
  294.     ... within 10 characters    Out.Int(i, 10)
  295. Write a real number    Out.Real(r, 0) or Out.LongReal(lr, 0)
  296. Write a string    Out.String(s)
  297. Write a new line character    Out.Ln
  298. Write a string containing one integer number    Out.F("$Value of x: #", x)
  299.     ... 2, 3, or 4 integer numbers    Out.F2("$x=#, y=#", x, y)
  300.     "$" is a new line character    Out.F3("$x=#, y=#, z=#", x, y, z)
  301.                 Out.F4("$x=#, y=#, a=#, b=#", x, y, a, b)
  302. Text1
  303. Syntax10.Scn.Fnt
  304. StyleElems
  305. Alloc
  306. Text2
  307. TwoCols
  308. LinkElems
  309. Alloc
  310. Prog.Guide.Text
  311. Prog.Guide.Text
  312. Module Input provides facilities to access the mouse, the keyboard, and the clock.
  313. Track the mouse    
  314. Try to read a character from keyboard    
  315. Get the time elapsed since system startup    seconds := Input.Time() DIV Input.TimeUnit
  316. Text1
  317. MarkElems
  318. Alloc
  319. Syntax10i.Scn.Fnt
  320. Syntax10.Scn.Fnt
  321. Syntax8i.Scn.Fnt
  322.     VAR text: Texts.Text;
  323. BEGIN
  324.     NEW(text); (* create an instance and install notifier *)
  325.     text.notify := TextFrames.NotifyDisplay;
  326.     Texts.Open(text, name); (* initialize text from file name *)
  327.     RETURN text
  328. END Text;
  329. Syntax10.Scn.Fnt
  330. Syntax8i.Scn.Fnt
  331. MarkElems
  332. Alloc
  333.     VAR r: Texts.Reader; ch: CHAR;
  334. BEGIN
  335.     IF pos < text.len THEN (* position is within the text *)
  336. Texts.OpenReader(r, text, pos);
  337.         Texts.Read(r, ch); (* read character at position pos *)
  338.         WHILE ~r.eot DO
  339.             (* process character ch *)
  340.             Texts.Read(r, ch)  (* read next character *)
  341.         END
  342. END ProcessText;
  343. Syntax10.Scn.Fnt
  344. Syntax8i.Scn.Fnt
  345. MarkElems
  346. Alloc
  347.     VAR r: Texts.Reader; ch: CHAR; Syntax10i: Fonts.Font;
  348. BEGIN
  349.     IF pos < text.len THEN
  350.         Syntax10i := Fonts.This("Syntax10i.Scn.Fnt");  (* the italics font *)
  351. Texts.OpenReader(r, text, pos);
  352.         Texts.Read(r, ch);  (* read first character *)
  353.         WHILE ~r.eot DO
  354.             IF r.fnt = Syntax10i THEN RETURN Texts.Pos(r) - 1 END;
  355.             Texts.Read(r, ch)  (* read next character *)
  356.         END
  357.     END;
  358.     RETURN -1
  359. END GetItalics;
  360. Syntax10.Scn.Fnt
  361. Syntax8i.Scn.Fnt
  362. MarkElems
  363. Alloc
  364.     VAR s: Texts.Scanner; ch: CHAR; name: ARRAY 256 OF CHAR; i: LONGINT;
  365. BEGIN
  366.     IF pos < text.len THEN (* position is within the text *)
  367. Texts.OpenScanner(s, text, pos);  (* set scanner to starting position *)
  368.         Texts.Scan(s);  (* scan a symbol *)
  369.         IF s.class = Texts.Name THEN
  370.             COPY(s.s, name)
  371.             (* process name *)
  372.         ELSIF s.class = Texts.Int THEN
  373.             i := s.i
  374.             (* process integer *)
  375.         END
  376. END ScanText;
  377. Syntax10.Scn.Fnt
  378. Syntax8i.Scn.Fnt
  379. MarkElems
  380. Alloc
  381. BEGIN
  382.     Texts.WriteString(w, txt);  (* append string txt to w.buf *)
  383.     Texts.WriteInt(w, i, 1);  (* convert i to text and append to w.buf *)
  384.     Texts.WriteLn(w);  (* append a carriage return character to w.buf *)
  385. Texts.Append(Oberon.Log, w.buf)  (* display w.buf in log *)
  386. END PutInt;
  387. Syntax10.Scn.Fnt
  388. MarkElems
  389. Alloc
  390. Syntax8i.Scn.Fnt
  391.     VAR s: Texts.Scanner; name: ARRAY 256 OF CHAR;
  392. BEGIN
  393. Texts.OpenScanner(s, 
  394. Oberon.Par.text, 
  395. Oberon.Par.pos);
  396.     Texts.Scan(s);
  397.     WHILE s.class = Texts.Name DO
  398.         COPY(name, s.s);
  399.         (* process object with name s.s *)
  400.         Texts.Scan(s)
  401. END ProcessNames;
  402. Syntax10.Scn.Fnt
  403. Syntax8i.Scn.Fnt
  404. MarkElems
  405. Alloc
  406.     VAR t: Texts.Text;  (* the text of the selection *)
  407.         beg, end: LONGINT;  (* the stretch in t which is selected *)
  408.         time: LONGINT;  (* the time of the most recent selection *)
  409. BEGIN
  410. Oberon.GetSelection(t, beg, end, time);
  411.     IF time > 0 THEN  (* the selection exists *)
  412.         (* process selection *)
  413. END ProcessSelection;
  414. Syntax10.Scn.Fnt
  415. Syntax8i.Scn.Fnt
  416. MarkElems
  417. Alloc
  418.     VAR s: Texts.Scanner; name: ARRAY 256 OF CHAR;
  419.         t: Texts.Text;  (* the text of the selection *)
  420.         beg, end: LONGINT;  (* the stretch in t which is selected *)
  421.         time: LONGINT;  (* the time of the most recent selection *)
  422. BEGIN
  423.     Texts.OpenScanner(s, 
  424. Oberon.Par.text, 
  425. Oberon.Par.pos);
  426.     Texts.Scan(s);
  427.     WHILE s.class = Texts.Name DO
  428.         COPY(name, s.s);
  429.         (* process object with name s.s *)
  430.         Texts.Scan(s)
  431.     END;
  432.     IF (s.class = Texts.Char) & (s.c = "^") THEN
  433.         Oberon.GetSelection(t, beg, end, time);
  434.         IF time > 0 THEN  (* the selection exists *)
  435.             Texts.OpenScanner(s, t, beg);
  436.             Texts.Scan(s);
  437.             IF s.class = Texts.Name THEN
  438.                 (* process object with name s.s *)
  439.             END
  440.         END
  441. END ProcessArgs;
  442. Syntax10i.Scn.Fnt
  443. Syntax10.Scn.Fnt
  444. MarkElems
  445. Alloc
  446.     VAR v: Viewers.Viewer; s: Texts.Scanner;
  447. BEGIN
  448.     Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos);
  449.     Texts.Scan(s);
  450.     IF (s.class = Texts.Char) & (s.c = "*") THEN
  451. v := Oberon.MarkedViewer();  (* does not require the star-shaped pointer to be visible *)
  452.         Viewers.Close(v)
  453. END Close;
  454. Syntax10i.Scn.Fnt
  455. Syntax10.Scn.Fnt
  456. MarkElems
  457. Alloc
  458.     VAR v: Viewers.Viewer; s: Texts.Scanner;
  459. BEGIN
  460.     Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos);
  461.     Texts.Scan(s);
  462.     IF (s.class = Texts.Char) & (s.c = "*") & Oberon.Pointer.on THEN  (* star-shaped must be visible *)
  463. v := Oberon.MarkedViewer(); 
  464.         Viewers.Close(v)
  465. END CloseVisible;
  466. Syntax10.Scn.Fnt
  467. Syntax8i.Scn.Fnt
  468. MarkElems
  469. Alloc
  470.     VAR f: TextFrames.Frame; t: Texts.Text; r: Texts.Reader; v: Viewers.Viewer;
  471.         beg, end, time: LONGINT;  (* time and stretch of selection *)
  472.         x, y: INTEGER;  (* position designated by the pointer *)
  473.         pos: LONGINT;  (* character equivalent of x, y *)
  474.         ch: CHAR;
  475. BEGIN
  476. Oberon.GetSelection(t, beg, end, time);  (* most recent selection *)
  477.     IF (time > 0)  (* selection exists *)
  478.         & Oberon.Pointer.on  (* pointer is visible *) THEN
  479. x := Oberon.Pointer.X; y := Oberon.Pointer.Y;
  480.         v := Viewers.This(x, y);  (* the viewer which contains the pointer *)
  481.         IF (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame) THEN  (* second frame is the text frame *)
  482. f := v.dsc.next(TextFrames.Frame);  (* the main frame *)
  483.             IF (y >= f.X) & (x < f.X + f.W) & (y >= f.Y) & (y < f.Y + f.H) THEN  (* pointer is in the main frame *)
  484.                 pos := TextFrames.Pos(f, x, y);  (* convert x, y to text position *)
  485.                 IF pos >= 0 THEN  (* position is valid *)
  486.                     Texts.OpenReader(r, f.text, pos);
  487.                     Texts.Read(r, ch);  (* read character at pos to access its font *)
  488.                     Texts.ChangeLooks(t, beg, end, {0}, r.fnt, 0, 0)  (* the font of the stretch [beg, end) is 
  489.                         changed and the display is updated *)
  490.                 END
  491.             END
  492.         END
  493.     END        
  494. END CopyFont;
  495. Syntax10.Scn.Fnt
  496. Syntax8i.Scn.Fnt
  497. MarkElems
  498. Alloc
  499.     VAR menuF, mainF: TextFrames.Frame;
  500.         txt: Texts.Text;  (* text of the main frame *)
  501.         v: MenuViewers.Viewer;
  502.         x, y: INTEGER;
  503. BEGIN
  504. txt := TextFrames.Text("");  (* create an empty text *)
  505.     menuF := TextFrames.NewMenu("New Viewer", "System.Close System.Copy System.Grow Edit.Store");
  506.     mainF := TextFrames.NewText(txt, 0);
  507. Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y);  (* placement hint *)
  508. v := MenuViewers.New(menuF, mainF, TextFrames.menuH, x, y)
  509. END OpenViewer;
  510. Syntax10.Scn.Fnt
  511. Syntax10i.Scn.Fnt
  512. Syntax8i.Scn.Fnt
  513. MarkElems
  514. Alloc
  515.     VAR txt: Texts.Text;  (* text to be processed *)
  516.         v: Viewers.Viewer; s: Texts.Scanner;
  517. BEGIN
  518. v := Oberon.Par.vwr;
  519.     IF (Oberon.Par.frame IS TextFrames.Frame) & (Oberon.Par.frame = v.dsc) THEN  
  520.         (* command is issued from menu *)
  521.         IF (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  522. txt := Oberon.Par.vwr.dsc.next(TextFrames.Frame).text
  523.             (* process text *)
  524.         END
  525.     ELSE (* command is issued from an editable text frame *)
  526.         Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos);
  527.         Texts.Scan(s);
  528.         WHILE s.class = Texts.Name DO
  529.             txt := TextFrames.Text(s.s);  (* open text from file with name s.s *)
  530.             (* process text *)
  531.             Texts.Scan(s)
  532.         END
  533.     END                    
  534. END ProcessText2;
  535. Syntax10.Scn.Fnt
  536. MarkElems
  537. Alloc
  538. Syntax8i.Scn.Fnt
  539.     VAR f: TextFrames.Frame; buf: Texts.Buffer; v: Viewers.Viewer; pos: LONGINT;
  540. BEGIN
  541. v := Oberon.FocusViewer;
  542.     IF (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  543.         (* Focus viewer has a main frame which is a text frame. *)
  544.         f := v.dsc.next(TextFrames.Frame);  (* the main frame *)
  545. IF f.hasCar THEN  (* a caret is set *)
  546.             Texts.Recall(buf);  (* the most recently deleted text *)
  547.             pos := f.carloc.pos + buf.len;  (* caret position after insert *)
  548. Texts.Insert(f.text, f.carloc.pos, buf);
  549. TextFrames.SetCaret(f, pos)
  550.         END
  551. END Recall;
  552. Syntax10.Scn.Fnt
  553. MarkElems
  554. Alloc
  555. Syntax8i.Scn.Fnt
  556.     VAR v: Viewers.Viewer; pos, carPos: LONGINT; f: TextFrames.Frame;
  557. BEGIN
  558. v := Oberon.MarkedViewer();
  559.     IF (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  560.         (* marked viewer has a main frame which is a text frame *)
  561. f := v.dsc.next(TextFrames.Frame);  (* the main frame *)
  562. IF f.hasCar THEN  (* a caret is displayed *)
  563.             carPos := f.carloc.pos
  564.         ELSE
  565.             carPos := 0
  566.         END;
  567.         pos := GetItalics(f.text, carPos);
  568.         IF pos < 0 THEN RETURN  (* no italics font found *)
  569.         ELSE
  570. Oberon.PassFocus(v);  (* request focus, clear caret if one is set *)
  571. TextFrames.RemoveSelection(f);
  572. Oberon.RemoveMarks(f.X, f.Y, f.W, f.H);
  573.             TextFrames.Show(f, pos - 200);  (* scroll viewer, positions the text near the top *)
  574. TextFrames.SetCaret(f, pos);  (* set the caret *)
  575.         END
  576. END SearchItalics;
  577. Syntax10.Scn.Fnt
  578. MarkElems
  579. Alloc
  580. Syntax8i.Scn.Fnt
  581. Syntax10i.Scn.Fnt
  582.     VAR file: Files.File;
  583. BEGIN
  584. file := Files.Old(name);  (* create file variable from directory entry name *)
  585.     IF file = NIL THEN  (* no entry name exists in the directory *)
  586. file := Files.New(name);  (* create new file *)
  587.     ELSE
  588.         (* process file *)
  589.     END;
  590.     (* ... *)
  591. Files.Register(file)  (* write buffers to disk and register file. In the case where the file is opened with Files.Old
  592.         there is no need to register the file, thus 
  593. Files.Close(f) would be enough. *)
  594.     (* The file is still valid after Files.Close or Files.Register is called! *)
  595. END ProcessFile;
  596. Syntax10.Scn.Fnt
  597.     VAR i, j: INTEGER;
  598. BEGIN
  599.     i := 0; j := 0;
  600.     LOOP
  601.         WHILE (name[i] # 0X) & (name[i] # ".") DO INC(i) END;
  602.         IF name[i] = 0X THEN EXIT END;
  603.         INC(i);
  604.         WHILE j # i DO bak[j] := name[j]; INC(j) END
  605.     END;
  606.     bak[j] := "B"; bak[j + 1] := "a"; bak[j + 2] := "k"; bak[j + 3] := 0X
  607. END Backup;
  608. Syntax10.Scn.Fnt
  609. Syntax8i.Scn.Fnt
  610.     VAR file: Files.File; bakName: ARRAY 32 OF CHAR; res: INTEGER;
  611. BEGIN
  612.     file := Files.New(name);  (* create an output file *)
  613.     (* ... *)
  614.     Backup(name, bakName);    (* create a backup name *)
  615.     Files.Rename(name, bakName, res);
  616.     CASE res OF
  617.         0:  (* file renamed *)
  618.     | 1: (* backup file already exists and is now associated with the old version of file name *)
  619.     | 2: (* name is not in directory *)
  620.     | 3: (* name is not well formed *)
  621.     END;
  622.     Files.Register(file)    (* register the newly created output file *)
  623. END Save;
  624. Syntax10.Scn.Fnt
  625. Syntax8i.Scn.Fnt
  626. MarkElems
  627. Alloc
  628.     TYPE
  629.         Person = POINTER TO PersonDesc;
  630.         PersonDesc = RECORD
  631.             Name: ARRAY 32 OF CHAR;
  632.             (* other fields *)
  633.         END;
  634.     VAR customer: Person;
  635.         r, w: Files.Rider; f: Files.File;
  636. BEGIN
  637.     f := Files.New("customer");
  638. Files.Set(r, f, 0);
  639.     Files.Set(w, f, 0);
  640.     (* ... *)
  641. Files.ReadBytes(r, customer^, SIZE(PersonDesc));  (* It is important to dereference the pointer *)
  642.     (* ... *)
  643. Files.WriteBytes(w, customer^, SIZE(PersonDesc));
  644.     (* ... *)
  645.     Files.Register(f)
  646. END RecordFile;
  647. Syntax10.Scn.Fnt
  648. Syntax10i.Scn.Fnt
  649.     VAR main: TextFrames.Frame; v: Viewers.Viewer;
  650. BEGIN
  651.     v := Oberon.MarkedViewer();
  652.     IF (v.dsc # NIL) & (v.dsc.next # NIL) & (v.dsc.next IS TextFrames.Frame) THEN
  653.         main := v.dsc.next(TextFrames.Frame);    (* main text frame of marked viewer *)
  654.         IF main.hasSel THEN
  655.             Texts.Delete(main.text, main.selbeg.pos, main.selend.pos)
  656.         END
  657. END Delete;
  658. Syntax10.Scn.Fnt
  659. Syntax10i.Scn.Fnt
  660. FoldElems
  661. Syntax10.Scn.Fnt
  662. time >= 0
  663. Syntax10.Scn.Fnt
  664. (v.dsc # NIL) & (v.dsc.next IS TextFrames.Frame)
  665. Syntax10.Scn.Fnt
  666. main.hasCar
  667.     VAR main: TextFrames.Frame; buf: Texts.Buffer; v: Viewers.Viewer; beg, end, time: LONGINT; t: Texts.Text;
  668. BEGIN
  669.     Oberon.GetSelection(t, beg, end, time);    (* get most recent selection *)
  670. selection exists
  671.  THEN
  672.         NEW(buf); Texts.OpenBuf(buf);
  673.         Texts.Save(t, beg, end, buf);    (* save text in buffer *)
  674.         v := Oberon.FocusViewer;    (* get focus viewer *)
  675.         IF 
  676. it is a text viewer
  677.  THEN
  678.             main := v.dsc.next(TextFrames.Frame);    (* main text frame *)
  679.             IF 
  680. caret exists
  681.  THEN
  682.                 Texts.Insert(main.text, main.carloc.pos, buf)    (* insert text at caret's position *)
  683.             END
  684.         END
  685. END CopyText;
  686. Syntax10.Scn.Fnt
  687. Syntax10i.Scn.Fnt
  688.     VAR keys: SET;
  689. BEGIN
  690.     REPEAT
  691.         (* procress keysum and mouse position (x, y) *)
  692.         Input.Mouse(keys, x, y);
  693.         Oberon.DrawCursor(Oberon.Mouse , Oberon.Arrow, x, y);
  694.         keysum := keysum + keys
  695.     UNTIL keys = {}
  696. END TrackMouse;
  697. Syntax10.Scn.Fnt
  698. BEGIN
  699.     IF Input.Available() = 0 THEN RETURN FALSE END;
  700.     Input.Read(ch);
  701.     RETURN TRUE
  702. END ReadChar;
  703. PopupElems
  704. Alloc
  705. Commandos
  706. Syntax10.Scn.Fnt
  707. Sample.OpenViewer
  708. Sample.Recall
  709. Sample.SearchItalics
  710. Sample.Delete
  711. Sample.CopyText
  712. Programming Guide
  713. based on M. Reiser: "The Oberon System"
  714. ssenb
  715. ck, C. Mayrhofer, C. Steindl
  716. Working with texts
  717. Accessing parameters
  718. Viewers
  719. Working with text viewers
  720. Working with text frames
  721. Working with files
  722. Input and Output
  723. Module In
  724. Module Out
  725. Module Input
  726. MODULE Sample;
  727. IMPORT Texts, TextFrames, Fonts, Oberon, Viewers, MenuViewers, Files, Input;
  728. VAR w: Texts.Writer;
  729. (* The following code is what TextFrames.Text actually does. *)
  730. PROCEDURE Text* (name: ARRAY OF CHAR): Texts.Text;
  731. (* Process all characters of a text, starting at position pos. *)
  732. PROCEDURE ProcessText (text: Texts.Text; pos: LONGINT);
  733. (* Searches a text from the initial position pos for the first occurrence of an italics font. It returns this position, if it exists, otherwise -1 results. *)
  734. PROCEDURE GetItalics (text: Texts.Text; pos: LONGINT): LONGINT;
  735. (* Scan a text, starting at position pos. *)
  736. (* When scanning a whole text, you can use ~s.eot as predicate in a WHILE loop as above, but s.eot may already yield TRUE while the last valid symbol is returned, not only after an attempt to scan beyond the end of the text. In this case, a WHILE loop using the predicate ~s.eot misses the last symbol. Therefore, it is always preferable to terminate a sequence of scan operations with a definite symbol. *)
  737. PROCEDURE ScanText (text: Texts.Text; pos: LONGINT);
  738. PROCEDURE PutInt* (txt: ARRAY OF CHAR; i: LONGINT);
  739. PROCEDURE ProcessNames*; (* {name} ~ *)
  740. PROCEDURE ProcessSelection*;  (* ^ *)
  741. PROCEDURE ProcessArgs*; (* {name} ~ | ^ *)
  742. PROCEDURE Close*; (* * *)
  743. PROCEDURE CloseVisible*; (* * *)
  744. (* Copies the font of the character underneath the star-shaped pointer to the selection *)
  745. PROCEDURE CopyFont*;
  746. PROCEDURE OpenViewer*;
  747. (* If the command is issued from an editable text, it admits a parameter list. All texts in the list will be processed. If, on the other hand, ProcessText2 is issued from the menu, it will work on the text contained in the main frame of the viewer which contains the menu. *)
  748. PROCEDURE ProcessText2*;
  749. (* The following code is what Edit.Recall actually does. *)
  750. PROCEDURE Recall*;
  751. (* The text of the main frame of the marked viewer is searched for the occurrence of a character in italics font Syntax10i.Scn.Fnt. The search is started at the caret position or at the beginning of the text if not caret is set. If a character is located, the text is scrolled such that it is displayed near the top line and the caret is positioned. *)
  752. PROCEDURE SearchItalics*;
  753. (* Try to open an old file, if none exists, create a new one *)
  754. PROCEDURE ProcessFile (name: ARRAY OF CHAR);
  755. PROCEDURE Backup (VAR name, bak: ARRAY OF CHAR);
  756. PROCEDURE Save (name: ARRAY OF CHAR);
  757. PROCEDURE RecordFile;
  758. (* Deletes the selected text in the marked viewer. *)
  759. PROCEDURE Delete*;
  760. (* Copies the most recently selected text part to the caret's position. *)
  761. PROCEDURE CopyText*;
  762. (* Tracks the mouse and process the mouse keys and the position *)
  763. PROCEDURE TrackMouse (VAR keysum: SET; VAR x, y: INTEGER);
  764. (* Try to read a character from keyboard *)
  765. PROCEDURE ReadChar (VAR ch: CHAR): BOOLEAN;
  766. BEGIN
  767.     Texts.OpenWriter(w)  (* The writer is based on the file system. In most cases, one writer per module is enough. It is, therefore, good practice to open the writer once per session in the module's body. *)
  768. END Sample.
  769. Compiler.Compile @/s
  770. ErrorElems.Mark    ErrorElems.Unmark    
  771.